package com.qk.management.controller;

import com.qk.result.PageResult;
import com.qk.result.Result;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/06 18:43
 * @Description: 角色管理控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/roles")
public class RoleController {

    private final RoleService roleService;
    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable Integer id) {
        roleService.deleteRole(id);
        return Result.success();
    }

    @PostMapping("")
    public Result insertRole(@RequestBody Role role) {
        roleService.insertRole(role);
        return Result.success();
    }

    @PutMapping("")
    public Result updateRole(@RequestBody Role role) {
        roleService.updateRole(role);
        return Result.success();
    }

    @GetMapping("/list")
    public Result selectRoles() {
        List<Role> roles = roleService.selectRoles();
        return Result.success(roles);
    }

    @GetMapping("{id}")
    public Result selectRoleById(@PathVariable Integer id) {
        Role role = roleService.selectRoleById(id);
        return Result.success(role);
    }

    @GetMapping("")
    public Result selectRolesByPage(RoleDTO roleDto) {
         PageResult<Role> pageResult = roleService.selectRolesByPage(roleDto);
        return Result.success(pageResult);
    }

}
